package com.example.peibei.base;

import com.dingtao.common.bean.User;
import com.dingtao.common.util.StringUtils;
import com.google.gson.Gson;
import com.tencent.mmkv.MMKV;

/**
 * @author dingtao
 * @date 2019-06-20 08:57
 * qq:1940870847
 */
public class SpConstant {
    public final static String LOGIN_USER_INFO = "login_user_info";
    @Deprecated
    public final static String USER_TOKEN = "token";
    @Deprecated
    public final static String USER_MID = "mid";
    @Deprecated
    public final static String PASSWORD = "password";
    @Deprecated
    public final static String PAY_PWD = "payPwd";
    @Deprecated
    public final static String CITY_NAME = "cityName";
    @Deprecated
    public final static String CITY_CODE = "cityCode";
    @Deprecated
    public final static String USER_SIG = "userSig";
    @Deprecated
    public final static String AUTH_CODE = "authCode";
    @Deprecated
    public final static String WX_ID = "wxOpenId";
    @Deprecated
    public final static String ZFB_ID = "zfbOpenId";
    @Deprecated
    public final static String WX_OPEN_ID = "wx_open_id";
    @Deprecated
    public final static String USER_AGREE = "userAgreement";
    @Deprecated
    public final static String AUTOID = "autoId";
    @Deprecated
    public final static String VIP = "vip";
    @Deprecated
    public final static String FIRST_NAME = "firstName";
    @Deprecated
    public final static String NICK_NAME = "nickName";


    public static void outLogin(){
        MMKV.defaultMMKV().encode(LOGIN_USER_INFO,new Gson().toJson(new User()));
    }

    public static void login(User user){
        if (user != null && user.getId() > 0){
            MMKV.defaultMMKV().encode(LOGIN_USER_INFO,new Gson().toJson(user));
        }
    }

    public static User getLoginUser(){
        String userData = MMKV.defaultMMKV().decodeString(LOGIN_USER_INFO,"{}");
        return new Gson().fromJson(userData,User.class);
    }
}
